package com.ujiuye.listener;

import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionBindingListener;

/**
 * java对象绑定和解绑session的监听器
 *  不需要加上注解，只针对当前student对象
 *
 *
 */


public class Student implements HttpSessionBindingListener {

    private String name;
    private int age;


    @Override
    public void valueBound(HttpSessionBindingEvent event) {
        //绑定   student对象只要添加到session中   绑定
        System.out.println("绑定");
        String name = event.getName();
        Object value = event.getValue();
        System.out.println(name + "...." + value);
    }

    @Override
    public void valueUnbound(HttpSessionBindingEvent event) {
        //解绑 student对象从session移除  解绑

        System.out.println("解绑");
        //解绑  获取的移除的键值对
        String name = event.getName();
        Object value = event.getValue();
        System.out.println(name + "...." + value);
    }

    public Student() {
    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
